package com.wish.g04.financing.kafka;

import com.wish.g04.common.redis.service.RedisService;
import com.wish.g04.financing.service.CheckBatchService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @author tianyandong
 */
@Component
@Slf4j
public class KafkaConsumer {

    @Autowired
    private RedisService redisService;

    @Autowired
    private CheckBatchService checkBatchService;

    @KafkaListener(topics = {"caiWu"},groupId = "wish-group")
    public void kafkaConsumer(ConsumerRecord<String, String> record, Acknowledgment acknowledgment) {
        String key = record.key();
        log.info("value:{}",record.value());
        if (!redisService.setCacheLock(key)) {
            log.info("kafka重复消费");
        }
        checkBatchService.checkAccount();
        acknowledgment.acknowledge();
    }


}
